home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mikie.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  186 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static int palettebank,flipscreen;
  15.  
  16.  
  17.  
  18. /***************************************************************************
  19.  
  20.   Convert the color PROMs into a more useable format.
  21.  
  22.   Mikie has three 256x4 palette PROMs (one per gun) and two 256x4 lookup
  23.   table PROMs (one for characters, one for sprites).
  24.   I don't know for sure how the palette PROMs are connected to the RGB
  25.   output, but it's probably the usual:
  26.  
  27.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  28.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  29.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  30.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  31.  
  32. ***************************************************************************/
  33. void mikie_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  34. {
  35.     int i;
  36.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  37.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  38.  
  39.  
  40.     for (i = 0;i < Machine->drv->total_colors;i++)
  41.     {
  42.         int bit0,bit1,bit2,bit3;
  43.  
  44.  
  45.         bit0 = (color_prom[0] >> 0) & 0x01;
  46.         bit1 = (color_prom[0] >> 1) & 0x01;
  47.         bit2 = (color_prom[0] >> 2) & 0x01;
  48.         bit3 = (color_prom[0] >> 3) & 0x01;
  49.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  50.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  51.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  52.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  53.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  54.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  55.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  56.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  57.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  58.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  59.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  60.  
  61.         color_prom++;
  62.     }
  63.  
  64.     color_prom += 2*Machine->drv->total_colors;
  65.     /* color_prom now points to the beginning of the character lookup table */
  66.  
  67.  
  68.     /* there are eight 32 colors palette banks; sprites use colors 0-15 and */
  69.     /* characters 16-31 of each bank. */
  70.     for (i = 0;i < TOTAL_COLORS(0)/8;i++)
  71.     {
  72.         int j;
  73.  
  74.  
  75.         for (j = 0;j < 8;j++)
  76.             COLOR(0,i + j * TOTAL_COLORS(0)/8) = (*color_prom & 0x0f) + 32 * j + 16;
  77.  
  78.         color_prom++;
  79.     }
  80.  
  81.     for (i = 0;i < TOTAL_COLORS(1)/8;i++)
  82.     {
  83.         int j;
  84.  
  85.  
  86.         for (j = 0;j < 8;j++)
  87.             COLOR(1,i + j * TOTAL_COLORS(1)/8) = (*color_prom & 0x0f) + 32 * j;
  88.  
  89.         color_prom++;
  90.     }
  91. }
  92.  
  93.  
  94.  
  95. WRITE_HANDLER( mikie_palettebank_w )
  96. {
  97.     if (palettebank != (data & 7))
  98.     {
  99.         palettebank = data & 7;
  100.         memset(dirtybuffer,1,videoram_size);
  101.     }
  102. }
  103.  
  104. WRITE_HANDLER( mikie_flipscreen_w )
  105. {
  106.     if (flipscreen != (data & 1))
  107.     {
  108.         flipscreen = data & 1;
  109.         memset(dirtybuffer,1,videoram_size);
  110.     }
  111. }
  112.  
  113.  
  114.  
  115. /***************************************************************************
  116.  
  117.   Draw the game screen in the given osd_bitmap.
  118.   Do NOT call osd_update_display() from this function, it will be called by
  119.   the main emulation engine.
  120.  
  121. ***************************************************************************/
  122. void mikie_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  123. {
  124.     int offs;
  125.  
  126.  
  127.     /* for every character in the Video RAM, check if it has been modified */
  128.     /* since last time and update it accordingly. */
  129.     for (offs = videoram_size - 1;offs >= 0;offs--)
  130.     {
  131.         int sx,sy,flipx,flipy;
  132.  
  133.         if (dirtybuffer[offs])
  134.         {
  135.             dirtybuffer[offs] = 0;
  136.  
  137.             sx = offs % 32;
  138.             sy = offs / 32;
  139.             flipx = colorram[offs] & 0x40;
  140.             flipy = colorram[offs] & 0x80;
  141.             if (flipscreen)
  142.             {
  143.                 sx = 31 - sx;
  144.                 sy = 31 - sy;
  145.                 flipx = !flipx;
  146.                 flipy = !flipy;
  147.             }
  148.  
  149.             drawgfx(tmpbitmap,Machine->gfx[0],
  150.                     videoram[offs] + ((colorram[offs] & 0x20) << 3),
  151.                     (colorram[offs] & 0x0f) + 16 * palettebank,
  152.                     flipx,flipy,
  153.                     8*sx,8*sy,
  154.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  155.         }
  156.     }
  157.  
  158.  
  159.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  160.  
  161.  
  162.     /* Draw the sprites. */
  163.     for (offs = 0;offs < spriteram_size;offs += 4)
  164.     {
  165.         int sx,sy,flipx,flipy;
  166.  
  167.         sx = spriteram[offs + 3];
  168.         sy = 244 - spriteram[offs + 1];
  169.         flipx = ~spriteram[offs] & 0x10;
  170.         flipy = spriteram[offs] & 0x20;
  171.         if (flipscreen)
  172.         {
  173.             sy = 242 - sy;
  174.             flipy = !flipy;
  175.         }
  176.  
  177.         drawgfx(bitmap,Machine->gfx[(spriteram[offs+2] & 0x40) ? 2 : 1],
  178.                 (spriteram[offs + 2] & 0x3f) + ((spriteram[offs + 2] & 0x80) >> 1)
  179.                         + ((spriteram[offs] & 0x40) << 1),
  180.                 (spriteram[offs] & 0x0f) + 16 * palettebank,
  181.                 flipx,flipy,
  182.                 sx,sy,
  183.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  184.     }
  185. }
  186.